package j03zuoye;

import java.util.*;

class Student{
    String name;
    int age;
    int score;
    String className;

    public Student(String name, int age, int score, String className) {
        this.name = name;
        this.age = age;
        this.score = score;
        this.className = className;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                ", className='" + className + '\'' +
                '}';
    }
}
public class Z3 {
    public static void main(String[] args) {
        /**
         * class05
         *     new Student("Tom",20,98,"class05")
         *     new Student("Owen",22,90,"class05"
         * class06
         *     ....
         */
        List<Student> studentList = new LinkedList<>();
        studentList.add(new Student("Tom",20,98,"class05"));
        studentList.add(new Student("Jerry",19,70,"class04"));
        studentList.add(new Student("Owen",22,90,"class05"));
        studentList.add(new Student("Jim",20,80,"class05"));
        studentList.add(new Student("Steve",21,66,"class06"));
        studentList.add(new Student("Kevin",22,95,"class04"));
        studentList.add(new Student("彭俊",21,95,"class04"));
        double ageSum = 0;
        for (Student temp:
             studentList) {
            ageSum += temp.age;
        }
        System.out.println("平均为："+ageSum/studentList.size());
        Map<String, ArrayList<Student>> map = new HashMap<>();
        for (Student temp:studentList) {
            String className = temp.className;
            if(!map.containsKey(className)){
                //没有此班级
                map.put(className,new ArrayList<>());
            }
            //班级存在
            List<Student> list = map.get(className);
            list.add(temp);
        }
        System.out.println(map);
        System.out.println("==各个班级平均值===");
        Set<String> classNameArr = map.keySet();
        for (String className:classNameArr) {
            double scoreSum = 0;
            List<Student> list = map.get(className);
            for (Student stu :list) {
                scoreSum += stu.score;
            }
            System.out.println(className+"班级平均成绩为："+scoreSum/list.size());
        }
    }

}
